home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
301-325
/
disk_313
/
uucp
/
uucp1.lzh
/
src
/
uucico
/
sysdep.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-10
|
11KB
|
608 lines
/*
* @(#)sysdep.amiga Version Amiga 0.1 87/09/20
*
* (C) Copyright 1987 by John Gilmore
* Copying and use of this program are controlled by the terms of the Free
* Software Foundation's GNU Emacs General Public License.
*
* Amiga Changes Copyright 1988 by William Loftus. All rights reserved.
* Additional chgs Copyright 1989 by Matthew Dillon, All Rights Reserved.
*/
#include "/version.h"
static char *Version = "@(#)sysdep.amiga gnuucp" VERSION ".01";
/*
* Split out of uuslave.c by John Gilmore, 8 August 1987.
* ported to the Amiga by William Loftus, 20 September 1987.
* rewritten by Matthew Dillon, October 1989
*/
/* FIXME -- System dependent defines (not really -- should be in a .h) */
/*
* Timeout for raw characters -- if we don't hear a char within BYTE_TIMEOUT
* seconds, we assume the other side has gone away. Has nothing to do with
* retransmission timeouts (if any!).
*/
extern int debug;
/* Amiga */
#include "uucp.h"
#include "modem.h"
#include <exec/types.h>
#include <ctype.h>
#include <fcntl.h>
#include <exec/exec.h>
#include <exec/devices.h>
#include <devices/serial.h>
#include <devices/keymap.h>
#include <devices/timer.h>
#include <hardware/cia.h>
#include <libraries/dos.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include <proto/exec.h>
#define NAMESIZE 128
#define FAILURE 1
void printc();
extern struct MsgPort *CreatePort();
struct IOExtSer Iosr;
struct IOExtSer Iosw;
struct IOExtSer Ioss;
struct timerequest Iot0;
char *OldTaskName;
char *DeviceName = "serial.device";
long DeviceUnit = 0;
unsigned char XInBuf[256]; /* for xgetc() */
short XInIdx = 0;
short XInLen = 0;
short IoswIP = 0;
short InExitRoutine = 0;
short debugRead = 0;
extern char path[];
extern int Getty;
extern int IgnoreCD;
void set_baud();
void OpenSerial();
void CloseSerial();
void xexit();
CXBRK()
{
return(0);
}
int
openout(acu, baud)
char *acu;
int baud;
{
set_baud(baud);
return SUCCESS;
}
/*
* Basement level I/O routines
*
* xwrite() writes a character string to the serial port
* xgetc() returns a character from the serial port, or an EOF for timeout.
* sigint() restores the state of the serial port on exit.
*/
int
sigint()
{
xexit(1);
return(0);
}
void
cleanup()
{
xexit(0);
}
int
xdatardy()
{
if (XInIdx != XInLen)
return(1);
CheckCarrier();
return (Ioss.IOSer.io_Actual > 0);
}
int
xgetc(byteto)
{
int ch, n;
long smask;
long tmask;
short bytetimeout;
top:
if (XInIdx != XInLen) {
if (debug > 8) {
if (debugRead == 0)
printf("\nREAD: ");
debugRead = 1;
printc(XInBuf[XInIdx]);
}
return((int)XInBuf[XInIdx++]);
}
XInIdx = 0;
XInLen = 0;
if (!CheckCarrier()) /* carrier lost? */
return(EOF);
if ((n = Ioss.IOSer.io_Actual) > 0) { /* at least one.. */
Iosr.IOSer.io_Command = CMD_READ;
Iosr.IOSer.io_Data = (APTR)XInBuf;
if (n > sizeof(XInBuf))
n = sizeof(XInBuf);
Iosr.IOSer.io_Length = n;
DoIO(&Iosr);
if (Iosr.IOSer.io_Actual > 0) {
if (debug > 8)
printf("(r%d/%d)", n, Iosr.IOSer.io_Actual);
XInIdx = 0;
XInLen = Iosr.IOSer.io_Actual;
goto top;
}
}
/*
* no bytes ready, wait for one.
*
* once every 3 seconds check carrier detect.
*/
bytetimeout = byteto;
Iot0.tr_time.tv_secs = 3;
Iot0.tr_time.tv_micro= 0;
SendIO(&Iot0);
Iosr.IOSer.io_Command = CMD_READ;
Iosr.IOSer.io_Data = (APTR)XInBuf;
Iosr.IOSer.io_Length = 1;
Iosr.IOSer.io_Actual = 0; /* trying to find a bug... */
SendIO(&Iosr);
smask = 1L << Iosr.IOSer.io_Message.mn_ReplyPort->mp_SigBit;
tmask = 1L << Iot0.tr_node.io_Message.mn_ReplyPort->mp_SigBit;
for (;;) {
long mask = Wait(tmask | smask | SIGBREAKF_CTRL_C);
if (mask & SIGBREAKF_CTRL_C) {
AbortIO(&Iosr);
WaitIO(&Iosr);
AbortIO(&Iot0);
WaitIO(&Iot0);
xexit(1);
}
if (CheckIO(&Iosr)) {
WaitIO(&Iosr);
AbortIO(&Iot0);
WaitIO(&Iot0);
ch = (int)XInBuf[0];
if (debug > 8) {
if (debugRead == 0)
printf("\nREAD ");
debugRead = 1;
printf("(waitc%d)", Iosr.IOSer.io_Actual);
printc(ch);
}
return(ch);
}
if (CheckIO(&Iot0)) {
WaitIO(&Iot0);
Iot0.tr_time.tv_secs = 3;
Iot0.tr_time.tv_micro= 0;
bytetimeout -= Iot0.tr_time.tv_secs;
if (bytetimeout > 0) {
if (CheckCarrier() == 0) {
AbortIO(&Iosr);
WaitIO(&Iosr);
break;
}
SendIO(&Iot0);
} else {
AbortIO(&Iosr);
WaitIO(&Iosr);
if (Iosr.IOSer.io_Actual == 1)
return((int)XInBuf[0]);
break;
}
}
}
if (debug > 8)
printf("\nRecv-EOF\n");
return(EOF);
}
xwrite(buf, ctr)
unsigned char *buf;
int ctr;
{
return(xxwrite(buf, ctr, 0));
}
xwritea(buf, ctr)
unsigned char *buf;
int ctr;
{
xxwrite(buf, ctr, 1);
return(ctr);
}
xxwrite(buf, ctr, async)
unsigned char *buf;
int ctr;
{
if (debug > 8) {
short i;
if (debugRead)
printf("\nWRITE ");
debugRead = 0;
for (i = 0; i < ctr; ++i) {
printc(buf[i]);
}
printf("\n");
}
if (IoswIP) {
WaitIO(&Iosw);
IoswIP = 0;
}
Iosw.IOSer.io_Command = CMD_WRITE;
Iosw.IOSer.io_Length = ctr;
Iosw.IOSer.io_Data = (APTR) &buf[0];
if (async) {
SendIO(&Iosw);
IoswIP = 1;
} else {
DoIO(&Iosw);
}
return ctr;
}
void
SendBreak()
{
Ioss.IOSer.io_Command = SDCMD_BREAK;
DoIO(&Ioss);
}
CheckCarrier()
{
Ioss.IOSer.io_Command = SDCMD_QUERY;
DoIO(&Ioss);
if (IgnoreCD)
return(1);
if (Ioss.io_Status & CIAF_COMCD) /* non-zero == no carrier */
return(0);
return(1);
}
void
bzero(s, cnt)
char *s;
int cnt;
{
int i;
for (i = 0; i < cnt; i++) {
*s++ = '\0';
}
}
void
bcopy(from, to, cnt)
char *from;
char *to;
int cnt;
{
int i;
for (i = 0; i < cnt; i++) {
*to++ = *from++;
}
}
/*
* Transform a filename from a uucp packet (in Unix format) into a local
* filename that will work in the local file system.
*/
void
munge_filename(s, d)
char *s, *d;
{
if (*s != '~') {
if (s != d)
strcpy(d, s);
return;
}
/*
* ~/ ... convert to UUPUB:
* ~user/... convert to <homedir>/...
*/
{
short i;
short c;
char *t;
struct passwd *pw;
for (i = 1; s[i] && s[i] != '/'; ++i);
c = s[i];
s[i] = 0;
if (i == 1)
pw = NULL;
else
pw = getpwnam(s + 1);
s[i] = c;
if (c == '/')
++i;
if (pw) {
t = malloc(strlen(pw->pw_dir) + strlen(s + i) + 1);
strcpy(t, pw->pw_dir);
} else {
t = malloc(strlen(s + i) + 32);
strcpy(t, "UUPUB:");
}
strcat(t, s + i);
strcpy(d, t);
free(t);
}
}
hangup()
{
reset_modem();
if (Execute("run >nil: <nil: uuxqt", NULL, NULL) == 0) {
if (Execute("run >nil: <nil: uucp:c/uuxqt", NULL, NULL) == 0)
puts("Unable to run UUXQT");
}
return SUCCESS;
}
static char names[3000];
static char *pointers[300];
static int file_pointer;
char *
work_scan(system_name)
char *system_name;
{
static char name[128];
int count;
file_pointer = 0;
if (strlen(system_name) > 7) {
system_name[7] = '\0';
}
sprintf(name,"UUSPOOL:C.%s#?", system_name);
if (debug > 2)
printf("Looking for %s\n",name);
count = getfnl(name,names,sizeof(names),0);
if (count > 0) {
if (strbpl(pointers,300,names) != count) {
printf("Too many command files for %s.\n",system_name);
return (char *)NULL;
}
} else {
return (char *)NULL;
}
if (debug > 2)
printf("Found -> %s\n", pointers[file_pointer]);
return (char *)1;
}
char *
work_next(system_name)
char *system_name;
{
if (debug > 2)
printf("Found -> %s\n", pointers[file_pointer]);
return pointers[file_pointer++];
}
/*
* Closing and openning the serial device drops DTR
*/
void
amiga_closeopen(str)
char *str;
{
CloseSerial();
Delay(60);
OpenSerial();
}
void
amiga_setup()
{
mountrequest(0); /* disallow requesters */
OpenSerial();
if (OpenDevice(TIMERNAME, UNIT_VBLANK, &Iot0, 0)) {
Iot0.tr_node.io_Device = NULL;
printf("Can't open timer device.");
xexit(1);
}
Iot0.tr_node.io_Message.mn_ReplyPort = CreatePort("UUCICO-Timer", 0L);
Iot0.tr_node.io_Command = TR_ADDREQUEST;
Iot0.tr_node.io_Error = 0;
{
struct Task *task = (struct Task *)FindTask(NULL);
OldTaskName = task->tc_Node.ln_Name;
task->tc_Node.ln_Name = "uucico";
}
}
void
set_baud(baud)
int baud;
{
Iosr.IOSer.io_Command = SDCMD_SETPARAMS;
Iosr.io_SerFlags = SERF_SHARED | SERF_XDISABLED;
Iosr.io_Baud = baud;
Iosr.io_ReadLen = 8L;
Iosr.io_WriteLen = 8L;
Iosr.io_CtlChar = 0x11130000L;
Iosr.io_RBufLen = 4096;
DoIO(&Iosr);
}
void
OpenSerial()
{
Iosr.io_SerFlags = SERF_SHARED | SERF_XDISABLED;
Iosr.IOSer.io_Message.mn_ReplyPort = CreatePort("Read_RS",0);
if (OpenDevice(DeviceName, DeviceUnit, &Iosr, NULL)) {
Iosr.IOSer.io_Device = NULL;
printf("Can not open serial port for read.\n");
xexit(TRUE);
}
/*
* Assume a Getty is running, if the opencount is > 2 then
* assume collision and disallow
*/
if (Iosr.IOSer.io_Device->dd_Library.lib_OpenCnt > 2) {
CloseDevice(&Iosr);
Iosr.IOSer.io_Device = NULL;
printf("Collision, serial port in use!\n");
xexit(TRUE);
}
/*
* The public port 'Lock-<spname>-<unit>' is used to lock the
* serial port (Getty will lock it this way while it is
* receiving an incomming call so if we are Getty assume it
* is already locked)
*/
if (Getty == 0)
LockSerialPort(DeviceName, DeviceUnit);
Iosw = Iosr;
Iosw.IOSer.io_Message.mn_ReplyPort = CreatePort("Write_RS", 0);
Ioss = Iosw;
Iosr.IOSer.io_Command = SDCMD_QUERY;
DoIO(&Iosr);
set_baud(Iosr.io_Baud);
}
void
CloseSerial()
{
if (IoswIP) {
WaitIO(&Iosw);
IoswIP = 0;
}
if (Iosr.IOSer.io_Device) {
CloseDevice(&Iosr);
Iosr.IOSer.io_Device = NULL;
if (Getty == 0)
UnLockSerialPort(DeviceName, DeviceUnit);
}
if (Iosr.IOSer.io_Message.mn_ReplyPort) {
DeletePort(Iosr.IOSer.io_Message.mn_ReplyPort);
Iosr.IOSer.io_Message.mn_ReplyPort = NULL;
}
if (Iosw.IOSer.io_Message.mn_ReplyPort) {
DeletePort(Iosw.IOSer.io_Message.mn_ReplyPort);
Iosw.IOSer.io_Message.mn_ReplyPort = NULL;
}
}
void
xexit(code)
{
++InExitRoutine;
if (InExitRoutine == 1 && code && Iosr.IOSer.io_Device && CheckCarrier())
reset_modem();
CloseSerial();
{
struct Task *task = (struct Task *)FindTask(NULL);
if (OldTaskName)
task->tc_Node.ln_Name = OldTaskName;
}
if (Iot0.tr_node.io_Device) {
CloseDevice(&Iot0);
Iot0.tr_node.io_Device = NULL;
}
if (Iot0.tr_node.io_Message.mn_ReplyPort) {
DeletePort(Iot0.tr_node.io_Message.mn_ReplyPort);
Iot0.tr_node.io_Message.mn_ReplyPort = NULL;
}
chdir(path);
if (code)
printf("\nAbnormal Termination.\n");
mountrequest(1);
UnLockFiles(); /* unlock any hanging locks */
exit(code);
}
void
printc(c)
unsigned char c;
{
c &= 0x7F;
if (c < 32)
printf("^%c", c | 0x40);
else if (c == 32)
printf("_");
else if (c < 128)
printf("%c", c);
else
printf("(%02x)", c);
}